package LeetCode.stack_queue;

import java.util.*;

public class RemoveElement {   // 用StringBuilder也可以
    public static void main(String[] args) {
        Deque<Character> stack = new LinkedList<>();
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(stack.isEmpty() || stack.peek() != c){
                stack.push(c);
            } else {
                stack.pop();
            }
        }
        if(stack.isEmpty()){
            return;
        }
        List<Character> list = new ArrayList<>();
        while (!stack.isEmpty()){
            list.add(stack.pop());
        }
        Collections.reverse(list);
    }
}
